// pages/APPLY/add/index.js
var app = getApp(), fetchApi = require("../../../utils/httpPost.js"), 
formatTime = require("../../../utils/formatTime.js"),
common_Js = require("../../../component/common.js");
import Dialog from '../../../component/vant/dialog/dialog';
import Toast from '../../../component/vant/toast/toast';

Page({
    /**
     * 页面的初始数据
     */
    data: {
      shopName:'',
      shopSwitch:false,
      searchKey: '',
        apply: {
          reqName:'',
          contactPhone:'',
          applyShopId:0,
          applyShopName:'',
          applyDeviceType:'',
        },
        shopList:[],
        deviceTypeChecked:[],
        user_id:0,
        submitState:false,
        record:{},
        record_id:0,
        show1:false,
        show2:false,
        show3:false,
        show4:false,
        show5:false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      if(options.id){
        this.data.record_id = parseInt(options.id);
    }
      this.onHttpInit()
    },

  /**
   * 获取页面数据的 http请求
   */
  onHttpInit: function () {
    console.log('onHttpInit')
    var that = this;
    fetchApi.httpPost('/apply/shop/device/record/detail', {
      record_id:that.data.record_id,
    }, function (res) {
      if (res.data.code == 0) {
        that.data.record = res.data.data.record
        if (that.data.record.applyDeviceType.indexOf('1') > -1) {
          that.data.show1 = true
        }
        if (that.data.record.applyDeviceType.indexOf('2') > -1) {
          that.data.show2 = true
        }
        if (that.data.record.applyDeviceType.indexOf('3') > -1) {
          that.data.show3 = true
        }
        if (that.data.record.applyDeviceType.indexOf('4') > -1) {
          that.data.show4 = true
        }
        if (that.data.record.applyDeviceType.indexOf('5') > -1) {
          that.data.show5 = true
        }
        that.setData({
            record: res.data.data.record,
            show1: that.data.show1,
            show2: that.data.show2,
            show3: that.data.show3,
            show4: that.data.show4,
            show5: that.data.show5
        })
      }
      that.setData({
         isLoading: false, loading: true, netWork: true,
      })
    }, function (res) {
        that.setData({ hasData: false,  isLoading: false,  loading: true, netWork: true })
    })
  },
  openTo(e){
    console.log('openTo',e);
    var that = this;
    var shopId = that.data.record.applyShopId;
    var type = e.currentTarget.dataset.id;
    var url = ''
    if (type == 1) {
      wx.navigateTo({
        url: '/pages/apply/device/index?shopId=' + shopId +'&shop_type= 4' + '&device_type=0' +'&position=1'
      })
    }else if (type == 2) {
      wx.navigateTo({
        url: '/pages/apply/device/index?shopId=' + shopId +'&shop_type= 10' + '&device_type=0' +'&position=3'
      })
    }else if (type == 3) {
      
    }else if (type == 4) {
      
    }else if (type == 5) {
      
    }
    // wx.navigateTo({ url: '/pages/apply/device/index?shopId=' + id +'&shop_type= ' + this.data.shop_type + '&device_type=' + this.data.deviceType+'&position=' + this.data.position }
  },
})